<?php
include("Conexao.php");
session_start();
session_destroy();
?>




<html>
    <head>
        
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
       <LINK REL=StyleSheet HREF="main.css" TYPE="text/css" MEDIA=screen>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>   
       <link rel="stylesheet" href="main.css" />

    </head>
    <body align ="center" style="text-align: center;">
        <br/>
        <div align="center" style="text-align: center; float: none  "> 
        <table border="0" width="80%" height="80%" align="center" style="text-align: center; border: 0px solid #ccc;">
               <tr align="center">
                    <td colspan="2"><?php include "cabecalhoAdmin.php"; ?></td>
                </tr>
                <tr>
                    
                    <td width="10%"></td>
                    <td width="90%">
                        <table border="0" align="left" width="80%">
                            <tr>
                                <td align="center">
                                  <?php 
                                  
                                      if(($_POST["cpf"] && $_POST["email"])  ){
                                         
                                          $conexao = new Conexao();

                                            $con = $conexao->conectBD();
                                            
                                            $sql = "SELECT nome,codigo FROM tbUsuario a INNER JOIN tbAdmin_equipe05 b ON a.codigo = b.idUsuario  
                                                WHERE a.cpf = '".$_POST["cpf"]."' AND a.email = '".$_POST["email"]."'"; // seleciona o usuario com perfil de administrador
                                                
                                            $result = pg_query($sql) or die ("ERRO");
                                            if(pg_num_rows($result) == 1){
                                                
                                                $colum = pg_fetch_array($result, 0);
                                                session_start();
                                                
                                                 $_SESSION["admin"] = $colum["nome"];
                                                 $_SESSION["id"] = $colum["codigo"];
                                                 header("Location:indexAdmin.php");
                                            }
                                            else
                                                 header("Location:loginAdmin.php?erro=USUÁRIO NAO ENCONTRADO!");
                                            
                                           // echo $sql;
                                            

                                      }
                                      else { 
                                          
                                            echo $_GET["erro"];
                                  ?> 
                                    
                                    <form name="loginAdmin" action="loginAdmin.php" method="POST">
                                    <table border="0" style="text-align: center; border: 1px solid #ccc;">
                                            <thead>
                                                <tr>
                                                    <th colspan="2">Acesso ao Sistema</th>
                                                    
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td> CPF:</td>
                                                    <td><input type="text" maxlength="11" name="cpf" value="" /></td>
                                                </tr>
                                                <tr>
                                                    <td>Email:</td>
                                                    <td><input type="text" name="email" value="" /></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2"><input type="submit" value="Entrar" /></td>
                                                   
                                                </tr>
                                                <tr>
                                                    <td></td>
                                                    <td></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </form>
                                      
                                      <?php   
                                      
                                      
                                      } ?>  
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"></td>
                    
                </tr>
                <tr>
                    <td colspan="2"><img src="images/footer2.jpg" width="100%" height="20"/></td>
                    
                </tr>
                <tr>
                    <td colspan="2" align="center">Trabalho de Banco de Dados I </br> Alunos: Urique Hoffmann , Kirmayr Roberto e Diana Lemos</td>
                    
                </tr>
        </table>
        </div>
    </body>
    
</html>




